//
//  ServiceShopCell.m
//  carowner
//
//  Created by apple on 2019/5/21.
//  Copyright © 2019 ggj. All rights reserved.
//

#import "ServiceShopCell.h"

@implementation ServiceShopCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if(self){
        _logoImage = [[UIImageView alloc] init];
        _logoImage.backgroundColor = gray_color;
        
        _shopName = [[UILabel alloc] init];
        _shopName.text = @"-";
        _shopName.textColor = title_color;
        _shopName.font = textFont;
        
        _btnPhone = [YLButton buttonWithType:UIButtonTypeCustom];
        [_btnPhone setTitle:@"电话" forState:UIControlStateNormal];
        [_btnPhone setTitleColor:tab_unselect_color forState:UIControlStateNormal];
        [_btnPhone setImage:[UIImage imageNamed:@"icon-png-tel"] forState:UIControlStateNormal];
        [_btnPhone setFont:textFont];
        _btnPhone.imageRect = CGRectMake(10, 10, 20, 20);
        _btnPhone.titleRect = CGRectMake(35, 10, 30, 20);
        _btnPhone.tag = 1;
        [_btnPhone addTarget:self action:@selector(itemClick:) forControlEvents:UIControlEventTouchUpInside];

        
        _btnOrder = [YLButton buttonWithType:UIButtonTypeCustom];
        [_btnOrder setTitle:@"预约" forState:UIControlStateNormal];
        [_btnOrder setTitleColor:tab_unselect_color forState:UIControlStateNormal];
        [_btnOrder setImage:[UIImage imageNamed:@"icon-png-yuyue"] forState:UIControlStateNormal];
        [_btnOrder setFont:textFont];
        _btnOrder.imageRect = CGRectMake(10, 10, 20, 20);
        _btnOrder.titleRect = CGRectMake(35, 10, 30, 20);
        _btnOrder.tag = 2;
        [_btnOrder addTarget:self action:@selector(itemClick:) forControlEvents:UIControlEventTouchUpInside];

        
        _btnNav = [YLButton buttonWithType:UIButtonTypeCustom];
        [_btnNav setTitle:@"导航" forState:UIControlStateNormal];
        [_btnNav setTitleColor:tab_unselect_color forState:UIControlStateNormal];
        [_btnNav setImage:[UIImage
                           imageNamed:@"icon-png-naviga"] forState:UIControlStateNormal];
        [_btnNav setFont:textFont];
        _btnNav.imageRect = CGRectMake(10, 10, 20, 20);
        _btnNav.titleRect = CGRectMake(35, 10, 30, 20);
        _btnNav.tag = 3;
        [_btnNav addTarget:self action:@selector(itemClick:) forControlEvents:UIControlEventTouchUpInside];

        
        _tvKm = [[UILabel alloc] init];
        _tvKm.textColor = tab_unselect_color;
        _tvKm.font = textFont;
        _tvKm.text = @"-km";
    
        _orderTime = [[UILabel alloc] init];
        _orderTime.textColor = tab_unselect_color;
        _orderTime.font = smallFont;
        _orderTime.text = @"服务时间";
        
        UIView * lineView = [NSObject getLineView];
        
        _addFav = [UIButton buttonWithType:UIButtonTypeCustom];
        [_addFav setTitle:@"加入收藏" forState:UIControlStateNormal];
        [_addFav setFont:textFont];
        [_addFav setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _addFav.backgroundColor = orange_color;
        _addFav.hidden = YES;
        _addFav.tag = 4;
        [_addFav addTarget:self action:@selector(itemClick:) forControlEvents:UIControlEventTouchUpInside];
    
        
        [self addSubview:_logoImage];
        [self addSubview:_shopName];
        [self addSubview:_btnPhone];
        [self addSubview:_btnOrder];
        [self addSubview:_btnNav];
        [self addSubview:_tvKm];
        [self addSubview:_orderTime];
        [self addSubview:lineView];
        [self addSubview:_addFav];
        
        [_logoImage mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self).offset(15);
            make.centerY.equalTo(self);
            make.size.mas_equalTo(CGSizeMake(90, 90));
        }];
        
        [_shopName mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(_logoImage);
            make.left.equalTo(_logoImage.mas_right).offset(10);
        }];
        
        [_btnPhone mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(_btnOrder.mas_top).offset(6);
            make.right.equalTo(self).offset(-15);
        }];
        
        [_btnOrder mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(self);
            make.right.equalTo(self).offset(-15);
        }];
        
        [_orderTime mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(_logoImage.mas_right).offset(10);
            make.bottom.equalTo(_logoImage);
        }];
        
        [_tvKm mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(_orderTime.mas_top).offset(-10);
            make.left.equalTo(_logoImage.mas_right).offset(10);
        }];
        
        [_btnNav mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(_orderTime.mas_top).offset(-10);
            make.left.equalTo(_tvKm.mas_right).offset(10);
        }];
        
        [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(self);
            make.left.right.equalTo(self);
            make.size.mas_equalTo(CGSizeMake(kScreen_Width, 1));
        }];
        
        [_addFav mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(_logoImage);
            make.right.equalTo(self).offset(-15);
            make.size.mas_equalTo(CGSizeMake(70, 26));
        }];
        
        
        
    }
    return self;
}


-(void)itemClick:(UIView *) view{
    [_delegate onItemClick:(int)view.tag withPos:_pos];
}

@end
